package com.sdkj.dspservice.common.utils;

import com.sdkj.dspservice.modules.demand.service.DemandService;
import com.sdkj.dspservice.modules.sys.entity.Menu;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * react工具类
 *
 * @author tm
 * @version 2020/12/30 15:47
 */
public class ReactUtils {

    private static DemandService demandService = SpringContextHolder.getBean(DemandService.class);

    /**
     * 制作react菜单数据
     * @param menuList
     * @return
     */
    public static List<Map<String, Object>> makeReactMenuData(List<Menu> menuList){
        List<Map<String, Object>> mapList = new ArrayList<>();
        for(Menu menu : menuList){
            Map<String, Object> map = new HashMap<>();
            map.put("name", menu.getName());
            map.put("title", menu.getName());
            map.put("path", menu.getHref());
            map.put("icon", menu.getIcon());
            map.put("locale", false);
            map.put("key", menu.getId());
            if("待处理需求".equals(menu.getName())){
                // 获取待办需求数量
                int count = demandService.getCountToDo();
                // 添加小红点
                map.put("badge", count);
            }
            if(menu.getChildren() != null && !menu.getChildren().isEmpty()){
                map.put("children", makeReactMenuData(menu.getChildren()));
            }
            mapList.add(map);
        }
        return mapList;
    }

}
